package org.springblade.modules.admin.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springblade.modules.admin.dto.BuildingUserContractDTO;
import org.springblade.modules.admin.dto.TlwBuildingElevatorQuery;
import org.springblade.modules.admin.dto.building.BuildingUserElevatorDTO;
import org.springblade.modules.admin.dto.platform.BuildingSearchDTO;
import org.springblade.modules.admin.dto.sugar.SugarSearchDTO;
import org.springblade.modules.admin.entity.Building;
import org.springblade.modules.admin.entity.BuildingUserContract;
import org.springblade.modules.admin.entity.MaintainPlanConfig;
import org.springblade.modules.admin.vo.*;
import org.springblade.modules.admin.vo.building.BuildingUserElevatorDetailVo;
import org.springblade.modules.admin.vo.erp.service.BuildingMessageVO;
import org.springblade.modules.admin.vo.feishu.GalaxyMaintainCustomerVO;
import org.springblade.modules.admin.vo.openapi.SidaBuildingBasicVO;
import org.springblade.modules.admin.vo.platform.BuildingSumVo;
import org.springblade.modules.admin.vo.platform.BuildingVo;
import org.springblade.modules.admin.vo.rescue.map.MapRescueBuildingDetailVO;
import org.springblade.modules.admin.vo.sugar.BuildingStatisticsListVO;
import org.springblade.modules.admin.vo.sugar.ChartItemVO;
import org.springblade.modules.admin.vo.sugar.bi.BILarkGroupSourceVO;
import org.springblade.modules.admin.vo.sugar.bi.BILarkRescueAreaResourceVO;
import org.springblade.modules.admin.vo.sugar.bi.BILarkRescueBigTableVO;
import org.springblade.modules.admin.vo.sugar.bi.BILarkRescueBuildingSourceVO;
import org.springblade.modules.admin.vo.tlw.TlwBuildingVO;
import org.springblade.modules.admin.vo.tlw.TlwElevatorEstateUserVO;
import org.springblade.modules.admin.vo.tlw.TlwElevatorVO;
import org.springblade.modules.system.entity.User;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface BuildingMapper extends BaseMapper<Building> {
    List<BuildingVO> selectBuildingPage(@Param("page") IPage<BuildingVO> page, @Param("building") Building building);

    BuildingVO selectBuilding(Long id);

    List<BuildingVO> buildingVOList(String tenantId);

    /**
     * 根据buildingId查询物业人员信息
     *
     * @param buildingId
     * @return
     */
    List<EstateUserInfoVO> selectEstateUserInfoByBuildingId(Long buildingId);

	/**
	 * 项目列表分页
	 * @param page
	 * @param building
	 * @return
	 */
	List<ProjectVO> selectProjectPage(@Param("page") IPage<ProjectVO> page, @Param("building") Building building);

	/**
	 * 根据项目id获取列表
	 * @param id 项目id
	 * @return 用户列表
	 */
    List<User> getUserListById(@Param("id") Long id);

	/**
	 * 获取电梯列表
	 * @param sugarSearchDTO 查询条件
	 * @return 数据集
	 */
	List<Building> getList(@Param("sugarSearchDTO") SugarSearchDTO sugarSearchDTO);

	/**
	 * 获取属性加结构
	 * @return
	 */
    List<BuildingTreeVo> treeList();

	/**
	 * 平台公共项目管理,分页列表
	 * @param page 分页信息
	 * @param building 查询条件
	 * @return 数据集
	 */
    IPage<BuildingVo> selectBuildingPageV2(IPage<BuildingVo> page, @Param("building") BuildingSearchDTO building);

	/**
	 * 获取项目汇总信息
	 * @return 数据集
	 */
	BuildingSumVo getBuildingSumInfo();

	/**
	 * 获取项目下拉列表
	 * @return
	 */
	List<BuildingSelectListVO> buildingSelectList();

	/**
	 * 梯联网-获取项目下拉列表
	 * @param search
	 * @return
	 */
	List<BuildingSelectListVO> buildingTlwSelectList(PlanConfigSearchVO search);

	/**
	 * 批量獲取
	 * @param ids
	 * @return
	 */
    List<BuildingVO> selectBuildingByIds(@Param("ids") List<Long> ids);

	/**
	 * 项目统计列表
	 * @param condition 3:已到期, 5即将到期 (对应blade_building_contract_plus表contract_status)
	 * @return
	 */
	List<BuildingStatisticsListVO> buildingStatisticsList(@Param("condition") Integer condition);

	/**
	 * 查询项目合同列表
	 * @return
	 */
	List<BuildingContractPlusVO> selectBuildingContractList();

	@Select("SELECT COUNT(DISTINCT b.NAME) FROM blade_elevator_device ed INNER JOIN blade_elevator e ON e.id=ed.elevator_id INNER JOIN blade_building b ON b.id=e.building_id WHERE ed.`status`=1 AND ed.device_id IS NOT NULL AND e.`status`=1 AND b.`status`=1 AND e.is_deleted = 0 AND ed.is_deleted = 0")
	Integer estateBuildingCountStatistics();

	/**
	 * 梯联网排行榜
	 *
	 * @param deviceList
	 * @return
	 */
	List<TlwRankingListVO> rankingList(@Param("deviceList") List<String> deviceList);

	/**
	 * 查询工单电梯数据统计
	 * @return
	 */
	List<ChartItemVO> selectPlanElevatorStatistics(@Param("tenantId") String tenantId);


	/**
	 * 获取当前物业下的项目信息
	 * @param building
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<Building> getList(Building building);


	/**
	 * 获取当前物业下的项目信息
	 * @param building
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<Building> getListByBuilding(Building building);

	/**
	 * 不区分租户查询
	 * @param buildingId 项目id
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine = "on")
	Building getById(Long buildingId);

    Map<String, Object> tlwBuildingElevatorCount(@Param("tbeQuery")TlwBuildingElevatorQuery tbeQuery);

	List<TlwBuildingVO> selectTlwBuildingPage(IPage<TlwBuildingVO> page,@Param("tbeQuery")TlwBuildingElevatorQuery tbeQuery);

	List<TlwElevatorVO> selectTlwElevatorList(@Param("tbeQuery")TlwBuildingElevatorQuery tbeQuery);

	/**
	 * 获取项目下拉列表
	 * @param search
	 * @return
	 */
    List<BuildingVO> selectSearchList(@Param("search") BuildingVO search);

	@InterceptorIgnore(tenantLine = "on")
	List<TlwBuildingVO> selectTlwBuilding(@Param("ids") List<Long> ids);

	@InterceptorIgnore(tenantLine = "on")
	List<TlwElevatorVO> selectTlwElevator(@Param("elevatorIds") List<Long> elevatorIds);

	@InterceptorIgnore(tenantLine = "on")
	List<TlwElevatorEstateUserVO> selectTlwEstateElevatorUser(Long userId);

	/**
	 * 获取项目（建筑）缓存所需 VO 列表
	 * @return 缓存所需 VO 列表
	 */
    List<BuildingRedisVO> listForRedisVO();

    MapRescueBuildingDetailVO selectMapRescueBuildingDetail(Long buildingId);

	/**
	 * 困人救援高发项目top10
	 * @param beginTime 开始时间
	 * @param endTime 结束时间
	 * @return buildingRescueScreenVO 列表
	 */
	List<BuildingRescueScreenVO> getRescueScreenB(@Param("beginTime") Date beginTime,@Param("endTime") Date endTime,@Param("elevatorIds") List<Long> elevatorIds);

	/**
	 * 困人救援高发电梯top10
	 * @param beginTime 开始时间
	 * @param endTime 结束时间
	 * @return elevatorRescueScreenVO 列表
	 */
	List<ElevatorRescueScreenVO> getRescueScreenE(Date beginTime, Date endTime);

	/**
	 * 困人救援高发场所
	 * @param beginTime 开始时间
	 * @param endTime 结束时间
	 * @param elevatorIds
	 * @return 复用Building的场所VO
	 */
	List<BuildingRescueScreenVO> getRescueScreenT(@Param("beginTime") Date beginTime,@Param("endTime") Date endTime,@Param("elevatorIds") List<Long> elevatorIds);

	/**
	 * 救援人员 top 10
	 * @param beginTime 开始时间
	 * @param endTime 结束时间
	 * @param sort 1：根据次数倒序 2：根据超时排序 3：根据平均时长排序
	 * @return 人VO列表
	 */
	List<UserRescueScreenVO> getRescueScreenU(Date beginTime, Date endTime, Integer sort);

	/**
	 * 项目-电梯占比
	 * @return 数量，占比业务层处理
	 */
    List<BuildingPercentageVO> buildingPercentage();

	/**
	 * 初始化查询
	 * @return
	 */
	List<BuildingESVO> listForEsInit();


	/**
	 * 获取项目的模板信息
	 * @param buildingId 项目id
	 * @return 数据集
	 */
	List<BuildingElevatorTemplateVO> selectBuildingElevatorTemplateByBuilding(Long buildingId);

	/**
	 * 获取银河维保客户信息
	 * @return 银河维保客户信息
	 */
	List<GalaxyMaintainCustomerVO> getGalaxyMaintainCustomerList();

	List<SidaBuildingBasicVO> getBuildingListByTenantId(String tenantId);

    List<BiBuildingVO> listBiBuildingList();


    List<BuildingMessageVO> selectBuildingMessageList();

	List<BuildingMessageVO> selectBuildingMessageByBuildingId(Long buildingId);

	List<BILarkRescueBigTableVO> getLarkRescueBigTable(Date startDate, Date endDate);

	List<BILarkRescueBigTableVO> getLarkRescueBigTableByCondition(Date startDate, Date endDate);

    List<BILarkGroupSourceVO> getLarkGroupSourceByCondition(Date startDate, Date endDate);

	List<BILarkRescueBuildingSourceVO> getLarkRescueBuildingSourceByCondition(Date startDate, Date endDate);

	List<BILarkRescueAreaResourceVO> getLarkRescueAreaResourceByCondition(Date startDate, Date endDate);

	List<BILarkRescueAreaResourceVO> getLarkRescueAreaPlaceByCondition(Date startDate, Date endDate);

    List<Building> listByH3Index();

    Building getByBuildingNameAndGroup(String buildingName, String groupId);

	List<Long> getBuildingIdsByGroupId(String groupId);


	/**
	 * 获取项目的合同统计信息
	 * @param buildingId 项目id
	 * @return 数据集
	 */
	List<MaintainPlanConfig> getBuildingStatus(Long buildingId);

	/**
	 * 获取项目列表
	 * @param page
	 * @param buildingUserContractDTO
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<BuildingUserContract> buildDingListV2(IPage<BuildingUserContract> page, BuildingUserContractDTO buildingUserContractDTO);

	List<MaintainPlanConfig> getBuildingUserStatus(@Param("buildingId") Long buildingId,@Param("timeType") Integer timeType);

	/**
	 *
	 * @param page 分页
	 * @param buildingUserDTO 查询
	 * @return 数据集
	 */
	List<BuildingUserElevatorDetailVo> elevatorListV2(@Param("page") IPage<BuildingUserElevatorDetailVo> page, @Param("buildingUserDTO") BuildingUserElevatorDTO buildingUserDTO);
}
